//-------------------------------------------------------------------------------------------------
// <copyright file="Registry_EditItem.cs" company="Microsoft">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// 
// <summary>
// Form to edit registry entry properties for DUAScriptGen.
// </summary>
//-------------------------------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace DUAScriptGen
{
	/// <summary>
	/// Summary description for Registry_EditItem.
	/// </summary>
	public class Registry_EditItem : System.Windows.Forms.Form
	{
		public DUARegistryEntry m_dRegEntry;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ComboBox cbRegRoot;
		private System.Windows.Forms.TextBox txtRegistryKeyName;
		private System.Windows.Forms.TextBox txtRegistryValue;
		private System.Windows.Forms.ComboBox cbRegValueDataType;
		private System.Windows.Forms.ComboBox cbActionToTake;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox txtRegValueData;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Registry_EditItem()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_dRegEntry = new DUARegistryEntry();
			
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.cbRegRoot = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtRegistryKeyName = new System.Windows.Forms.TextBox();
			this.txtRegistryValue = new System.Windows.Forms.TextBox();
			this.cbRegValueDataType = new System.Windows.Forms.ComboBox();
			this.cbActionToTake = new System.Windows.Forms.ComboBox();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.txtRegValueData = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// cbRegRoot
			// 
			this.cbRegRoot.Items.AddRange(new object[] {
														   "HKEY_CLASSES_ROOT",
														   "HKEY_CURRENT_USER",
														   "HKEY_LOCAL_MACHINE",
														   "HKEY_USERS",
														   "HKEY_PERFORMANCE_DATA",
														   "HKEY_CURRENT_CONFIG"});
			this.cbRegRoot.Location = new System.Drawing.Point(152, 16);
			this.cbRegRoot.Name = "cbRegRoot";
			this.cbRegRoot.Size = new System.Drawing.Size(256, 21);
			this.cbRegRoot.TabIndex = 3;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 18);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 2;
			this.label1.Text = "Registry root:";
			// 
			// txtRegistryKeyName
			// 
			this.txtRegistryKeyName.Location = new System.Drawing.Point(152, 61);
			this.txtRegistryKeyName.Name = "txtRegistryKeyName";
			this.txtRegistryKeyName.Size = new System.Drawing.Size(256, 20);
			this.txtRegistryKeyName.TabIndex = 5;
			this.txtRegistryKeyName.Text = "";
			// 
			// txtRegistryValue
			// 
			this.txtRegistryValue.Location = new System.Drawing.Point(152, 105);
			this.txtRegistryValue.Name = "txtRegistryValue";
			this.txtRegistryValue.Size = new System.Drawing.Size(256, 20);
			this.txtRegistryValue.TabIndex = 7;
			this.txtRegistryValue.Text = "";
			// 
			// cbRegValueDataType
			// 
			this.cbRegValueDataType.Items.AddRange(new object[] {
																	"REG_SZ",
																	"REG_EXPAND_SZ",
																	"REG_BINARY",
																	"REG_DWORD ",
																	"REG_DWORD_BIG_ENDIAN",
																	"REG_LINK",
																	"REG_MULTI_SZ",
																	"REG_RESOURCE_LIST",
																	"REG_QWORD ",
																	"REG_QWORD_LITTLE_ENDIAN",
																	"REG_NONE"});
			this.cbRegValueDataType.Location = new System.Drawing.Point(152, 193);
			this.cbRegValueDataType.Name = "cbRegValueDataType";
			this.cbRegValueDataType.Size = new System.Drawing.Size(256, 21);
			this.cbRegValueDataType.TabIndex = 11;
			// 
			// cbActionToTake
			// 
			this.cbActionToTake.Items.AddRange(new object[] {
																"Create key",
																"Create key and add value",
																"Delete key",
																"Delete value",
																"Restore key",
																"Save key"});
			this.cbActionToTake.Location = new System.Drawing.Point(152, 238);
			this.cbActionToTake.Name = "cbActionToTake";
			this.cbActionToTake.Size = new System.Drawing.Size(256, 21);
			this.cbActionToTake.TabIndex = 13;
			this.cbActionToTake.SelectedIndexChanged += new System.EventHandler(this.cbActionToTake_SelectedIndexChanged);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(256, 280);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(72, 24);
			this.btnOK.TabIndex = 0;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.OK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(336, 280);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(72, 24);
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.Cancel_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 63);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 4;
			this.label2.Text = "Registry key:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 107);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(112, 16);
			this.label3.TabIndex = 6;
			this.label3.Text = "Registry value name:";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 195);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(136, 16);
			this.label4.TabIndex = 10;
			this.label4.Text = "Registry value data type:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 240);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(104, 16);
			this.label5.TabIndex = 12;
			this.label5.Text = "DUA action to take:";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(8, 151);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(112, 16);
			this.label6.TabIndex = 8;
			this.label6.Text = "Registry value data:";
			// 
			// txtRegValueData
			// 
			this.txtRegValueData.Location = new System.Drawing.Point(152, 149);
			this.txtRegValueData.Name = "txtRegValueData";
			this.txtRegValueData.Size = new System.Drawing.Size(256, 20);
			this.txtRegValueData.TabIndex = 9;
			this.txtRegValueData.Text = "";
			// 
			// Registry_EditItem
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(424, 318);
			this.Controls.Add(this.txtRegValueData);
			this.Controls.Add(this.txtRegistryValue);
			this.Controls.Add(this.txtRegistryKeyName);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.cbActionToTake);
			this.Controls.Add(this.cbRegValueDataType);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.cbRegRoot);
			this.MaximizeBox = false;
			this.Name = "Registry_EditItem";
			this.ShowInTaskbar = false;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
			this.Text = "Edit Registry Data Item";
			this.Load += new System.EventHandler(this.Registry_EditItem_Load);
			this.ResumeLayout(false);

		}
		#endregion


		/*****************************************************************************************
		Function Name:	Cancel_Click
		Author:			aaronste
		Description:	Handler for the cancel button click action
		Inputs:			object sender - calling object
						System.EventArgs e - container for additional arguments for this event
		Outputs:		none
		******************************************************************************************/
		private void Cancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult=DialogResult.Cancel;
			this.Close( );
		}


		/*****************************************************************************************
		Function Name:	OK_Click
		Author:			aaronste
		Description:	Handler for the OK button click action
		Inputs:			object sender - calling object
						System.EventArgs e - container for additional arguments for this event
		Outputs:		none
		******************************************************************************************/
		private void OK_Click(object sender, System.EventArgs e)
		{
			// Update the DUARegistryEntry member variable for use by the owner of this dialog
			m_dRegEntry.m_iRegRoot = cbRegRoot.SelectedIndex;
			m_dRegEntry.m_iRegValueDataType = cbRegValueDataType.SelectedIndex;
			m_dRegEntry.m_iRegistryOperation = cbActionToTake.SelectedIndex;

			m_dRegEntry.m_strRegKeyName = "";
			m_dRegEntry.m_strRegValueName = "";
			m_dRegEntry.m_strRegValueData = "";

			// Only set the text for the key, value and value data if the textbox is
			// enabled (meaning that a valid DUA action for this data value was chosen
			if (true == txtRegistryKeyName.Enabled)
				m_dRegEntry.m_strRegKeyName = txtRegistryKeyName.Text.Trim();

			if (true == txtRegistryValue.Enabled)
				m_dRegEntry.m_strRegValueName = txtRegistryValue.Text.Trim();

			if (true == txtRegValueData.Enabled)
				m_dRegEntry.m_strRegValueData = txtRegValueData.Text.Trim();

			// Set the dialog result and exit
			this.DialogResult=DialogResult.OK;
			this.Close( );
		}


		/*****************************************************************************************
		Function Name:	Registry_EditItem_Load
		Author:			aaronste
		Description:	Handler for the OK button click action
		Inputs:			object sender - calling object
						System.EventArgs e - container for additional arguments for this event
		Outputs:		none
		******************************************************************************************/
		private void Registry_EditItem_Load(object sender, System.EventArgs e)
		{
			// Set default UI values based on DUARegistryEntry member variable
			cbRegRoot.SelectedIndex = m_dRegEntry.m_iRegRoot;
			cbRegValueDataType.SelectedIndex = m_dRegEntry.m_iRegValueDataType;
			cbActionToTake.SelectedIndex = m_dRegEntry.m_iRegistryOperation;
			
			txtRegistryKeyName.Text = m_dRegEntry.m_strRegKeyName;
			txtRegistryValue.Text = m_dRegEntry.m_strRegValueName;
			txtRegValueData.Text = m_dRegEntry.m_strRegValueData;
		}


		/*****************************************************************************************
		Function Name:	cbActionToTake_SelectedIndexChanged
		Author:			aaronste
		Description:	Handler for the selected DUA action dropdown selection change event
		Inputs:			object sender - calling object
						System.EventArgs e - container for additional arguments for this event
		Outputs:		none
		******************************************************************************************/
		private void cbActionToTake_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int iSelectedIndex = cbActionToTake.SelectedIndex;

			// Disable or enable registry value areas based on what action is selected
			switch (iSelectedIndex)
			{
				case ((int)E_REGISTRYOPERATION.Create):
					txtRegistryValue.Enabled = false;
					txtRegValueData.Enabled = false;
					cbRegValueDataType.Enabled = false;
					break;

				case ((int)E_REGISTRYOPERATION.CreateAndAddValue):
					txtRegistryValue.Enabled = true;
					txtRegValueData.Enabled = true;
					cbRegValueDataType.Enabled = true;
					break;

				case ((int)E_REGISTRYOPERATION.DeleteKey):
					txtRegistryValue.Enabled = false;
					txtRegValueData.Enabled = false;
					cbRegValueDataType.Enabled = false;
					break;

				case ((int)E_REGISTRYOPERATION.DeleteValue):
					txtRegistryValue.Enabled = true;
					txtRegValueData.Enabled = true;
					cbRegValueDataType.Enabled = false;
					break;

				case ((int)E_REGISTRYOPERATION.RestoreKey):
					txtRegistryValue.Enabled = false;
					txtRegValueData.Enabled = false;
					cbRegValueDataType.Enabled = false;
					break;

				case ((int)E_REGISTRYOPERATION.SaveKey):
					txtRegistryValue.Enabled = false;
					txtRegValueData.Enabled = false;
					cbRegValueDataType.Enabled = false;
					break;

				default:
					break;

			}
		}

	}
}
